package cn.itcast.crm.controller;

import cn.itcast.bos.domain.common.ResponseResult;
import cn.itcast.bos.domain.crm.Customer;
import cn.itcast.crm.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Administrator on 2018/12/27.
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    CustomerService customerService;

    @RequestMapping("/findNoAssociationCustomers")
    @CrossOrigin(origins="http://localhost:9001",allowCredentials="true")
    public List<Customer> findNoAssociationCustomers(){
        return customerService.findNoAssociationCustomers();
    }

    @RequestMapping("/findHasAssociationFixedAreaCustomers")
    @CrossOrigin(origins="http://localhost:9001",allowCredentials="true")
    public List<Customer> findHasAssociationFixedAreaCustomers(String fixedAreaId){
        return customerService.findHasAssociationFixedAreaCustomers(fixedAreaId);
    }

    // 关联客户到定区
    @RequestMapping("/associationCustomersToFixedArea")
    @CrossOrigin(origins="http://localhost:9001",allowCredentials="true")
    public ResponseResult associationCustomersToFixedArea(String[] customerIds,String id) {

        try {
            customerService.associationCustomersToFixedArea(customerIds,id);
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseResult.FAIL();
        }
        return ResponseResult.SUCCESS();
    }


}
